﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="format-detection" content="telephone=no">  
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <title>KM报表平台登录</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/signin.css" rel="stylesheet">
    <script src="js/jquery/jquery-1.8.1.min.js" type="text/javascript"></script>
    <script src="js/config.js" type="text/javascript"></script>
    <script src="js/Toast.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            //检查版本更新。
            getupdate();
            $("#aa").live("click", function () {
                login2();
            });
            $("#usercode").keydown(function (event) {
                if (event.which == 13) {
                    if ($.trim($("#usercode").val()) == "") {
                        showtoast("用户名不能为空！", null, null, null);
                        $("#usercode").focus();
                    } else {
                        $("#userpwd").focus();
                    }
                }
            });
            $("#userpwd").keydown(function (event) {
                if (event.which == 13) {
                    login2();
                }
            });
        });
        //ajax登录方法
        function login2() {
            var ucode = $.trim($("#usercode").val());
            var upwd = $.trim($("#userpwd").val());
            if (ucode == "") {
                //alert("用户名不能为空！");
                showtoast("用户名不能为空！", null,100,100);
                return;
            }
            if (upwd == "") {
                showtoast("密码不能为空！", null, 100, 100);
                //alert("密码不能为空！");
                return;
            }
            $.ajax({
                url: url_path + "/ajaxdata/login.aspx",
                type: "POST",
                data: { aciton: 'Login', UserCode: ucode, UserPwd: upwd, LoginType: my_ClientType },
                timeout: 30000,
                dataType: "text",
                success: function (data) {
                    if (data == "user_stop") {
                        showtoast("该用户已停用，请重新登录！", null, 100, 100);
                    } else if (data == "err_text") {
                        showtoast("用户名或密码错误！", null, 100, 100);
                    } else {
                        var msg = $.trim(data);
                        var orderObj = JSON.parse(msg);
                        for (var i = 0; i < orderObj.length; i++) {
                            //储存到本地
                            localStorage.removeItem("UserID");
                            localStorage.removeItem("UserCode");
                            localStorage.removeItem("UserName");
                            localStorage.setItem("UserID", orderObj[i].UserID);
                            localStorage.setItem("UserCode", orderObj[i].UserCode);
                            localStorage.setItem("UserName", orderObj[i].UserName);

                            USER_ID = orderObj[i].UserID;
                            UserCode = orderObj[i].UserCode;
                            UserName = orderObj[i].UserName;
                        }
                        //var sessionId = window.sessionStorage.getItem("sessionID");
                        //window.sessionStorage.removeItem("sessionID"); 

                        window.location.href = './index.html';
                    }
                },
                error: function () {
                    showtoast("通讯超时,请检查网络.", null, 100, 100);
                }
            });
        }
        //获取最新版本信息
        function getupdate() {
            $.post(url_path + "/ajaxdata/login.aspx", { aciton: "getupdate", ClientType: my_ClientType, Version: my_Version },
             function (data) {
                 if (data != "") {
                     var update_arry = eval("[" + data + "]");
                     if (update_arry[0].version != my_Version) {
                         alert("有新版本发布请到App Store下载更新！")
                     }
                 }

             });
        }
    </script>
</head>
<body id="homepage">
    <div class="signin">
        <div class="signin-head">
            <span style="font-size: 38px;">KM报表平台</span><br />
            <span>© 2015快速反应V1.0</span>
        </div>
        <form class="form-signin">
        <input id="usercode" type="text" class="form-control" placeholder="用户名" required
            autofocus />
        <input id="userpwd" type="password" class="form-control" placeholder="密码" required />
        <a id="aa" class="btn  btn-lg btn-warning btn-block" href="#">登录</a>
        </form>
    </div>
</body>
</html>
